# 导入
import requests


# 进行登陆
response = requests.post(url="http://ihrm-test.itheima.net/api/sys/login",
                         headers={"Content-Type": "application/json"},
                         json={"mobile": "13800000002",
                               "password": "123456"})

# 打印登陆的结果
print(response.json())

# 提取令牌
token = "Bearer " + response.json().get("data")
print("提取到的令牌为：", token)

import app

print("app.HEADERS没有设置令牌之前的结果为：", app.HEADERS)
# app.HEADERS['Authorization'] = token  # 把令牌放在全局变量app.py下的HEADERS中
print("app.HEADERS的结果为", app.HEADERS)
# 从第17行开始，后续所有的代码，都可以使用app.HEADERS中的令牌

# 实现添加员工
add_emp_url = "http://ihrm-test.itheima.net/api/sys/user"
response = requests.post(url=add_emp_url, headers=app.HEADERS,
                         json={"username": "比卡丘",
                               "mobile": "173121238945",
                               "timeOfEntry": "2020-08-04",
                               "formOfEmployment": 1,
                               "departmentName": "111",
                               "correctionTime": "2020-08-09T16:00:00.000Z"})
print("添加员工的结果为:", response.json())
